package com.easybacklog.client.webservices.subversion;

import com.easybacklog.client.model.Project;
import com.easybacklog.client.repositoryLogin.EncryptText;
import com.easybacklog.client.repositoryLogin.GetCookies;
import com.google.gwt.http.client.Request;
import com.google.gwt.http.client.RequestBuilder;
import com.google.gwt.http.client.RequestCallback;
import com.google.gwt.http.client.RequestException;
import com.google.gwt.http.client.Response;

public class RequestUpdateSubversionSpecificationFile {

	// http://livesourceagile.com:8080/LiveSourceWebServices/SaveSubversionSpecificationFileService
	// ?repositoryURL=https://tictactoe4j.googlecode.com/svn/trunk
	// &username=alline.oliveira&password=bD8Km8se2rV9
	// &projectID=tictactoe4j

	private static String url = "http://livesourceagile.com:8080/LiveSourceWebServices/SaveSubversionSpecificationFileService";

	public static void sendPostRequest(Project project) {

		String username = EncryptText.decrypt(GetCookies.getUsername(project
				.getProjectID()));

		if (username != null) {

			String password = EncryptText.decrypt(GetCookies
					.getPassword(project.getProjectID()));

			String urlSave = url + "?repositoryURL="
					+ project.getRepositoryURL() + "&username=" + username
					+ "&password=" + password + "&projectID="
					+ project.getProjectID();

			RequestBuilder builder = new RequestBuilder(RequestBuilder.POST,
					urlSave);

			// builder.setRequestData(requestData);

			try {
				Request request = builder.sendRequest(null,
						new RequestCallback() {

							public void onError(Request request,
									Throwable exception) {
								// displayError("Couldn't retrieve JSON");
							}

							public void onResponseReceived(Request request,
									Response response) {

								if (200 == response.getStatusCode()) {
									// updateTable(asArrayOfStockData(response.getText()));
								} else {
									// displayError("Couldn't retrieve JSON ("
									// + response.getStatusText() + ")");
								}
							}
						});

			} catch (RequestException e) {
				// displayError("Couldn't retrieve JSON");
			}
		}
	}
}